FROM python:3.6-alpine

LABEL description="ElastAlert suitable for Kubernetes and Helm"
LABEL maintainer="lixiaoxia"

ARG ELASTALERT_VERSION=0.2.4

RUN apk --update upgrade && \
    apk add gcc libffi-dev musl-dev python3-dev openssl-dev tzdata libmagic && \
    rm -rf /var/cache/apk/*

RUN pip install elastalert==${ELASTALERT_VERSION} && \
    apk del gcc libffi-dev musl-dev python3-dev openssl-dev

RUN mkdir -p /opt/elastalert && \
    mkdir -p /opt/elastalert/elastalert_modules && \
    echo "#!/bin/sh" >> /opt/elastalert/run.sh && \
    echo "set -e" >> /opt/elastalert/run.sh && \
    echo "elastalert-create-index --config /opt/config/elastalert_config.yaml" >> /opt/elastalert/run.sh && \
    echo "exec elastalert --config /opt/config/elastalert_config.yaml \"\$@\"" >> /opt/elastalert/run.sh && \
    chmod +x /opt/elastalert/run.sh

ENV TZ "UTC"

WORKDIR /opt/elastalert

COPY  elastalert_modules/dingtalk_alert.py   /opt/elastalert/elastalert_modules
COPY  elastalert_modules/__init__.py   /opt/elastalert/elastalert_modules
COPY ./entrypoint.sh /opt/elastalert/
COPY conf/elastalert_config.yaml /opt/config/
COPY conf/rule.yaml /opt/elastalert/rules/
COPY conf/rule_spare_error.yaml /opt/elastalert/rules/
COPY conf/smtp_auth_file.yaml /opt/config/
RUN  chmod +x /opt/elastalert/entrypoint.sh
CMD ["sh", "/opt/elastalert/entrypoint.sh"]